import { BasicFetchResult } from '/@/api/model/baseMode';
import { defHttp } from '/@/utils/http/axios';
import { UploadFileParams, UploadApiResult } from './model';
import { ErrorMessageMode } from '/@/utils/http/axios/types';

enum Api {
  // List = '/bannerManager/findPage',
  List = '/baseinfo/articleManager/findPage',
  Add = '/baseinfo/articleManager/add',
  Delete = '/baseinfo/articleManager/delete',
  Edit = '/baseinfo/articleManager/edit',
  Update = '/baseinfo/articleManager/update',
  Upload = '/baseinfo/articleManager/getFileUrl',
}

/**
 * @description: 查询广告位列表
 */
export function ListApi(params, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<BasicFetchResult<any>>(
    {
      url: Api.List,
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

/**
 * @description: 新增用户
 */
export function AddApi(params, mode: ErrorMessageMode = 'modal') {
  return defHttp.post(
    {
      url: Api.Add,
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

/**
 * @description: 编辑文章
 */
export function UpdateApi(params, mode: ErrorMessageMode = 'modal') {
  return defHttp.post(
    {
      url: Api.Update,
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

/**
 * @description: 删除文章
 */
export function DeleteApi(userId: any, mode: ErrorMessageMode = 'modal') {
  return defHttp.delete(
    {
      url: Api.Delete + `/${userId}`,
    },
    {
      errorMessageMode: mode,
    }
  );
}

/**
 * @description: 上下线
 */
export function EditApi(params, mode: ErrorMessageMode = 'modal') {
  return defHttp.put(
    {
      url: Api.Edit,
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

/**
 * @description: 上传banner图片
 */
export function UploadApi(
  params: UploadFileParams,
  onUploadProgress: (progressEvent: ProgressEvent) => void
) {
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: Api.Upload,
      onUploadProgress,
    },
    params
  );
}
